package Demo16_30.Test24;

import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

/**
 * Created by 14229 on 2020/1/29.
 */
public class Test {
    public static void main(String[] args) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {

        Properties pro =new Properties();
        FileInputStream fis =new FileInputStream("data.properties");

        pro.load(fis);

        fis.close();

        Class<?> aClass = Class.forName("Demo16_30.Test24.User");
        Object o = aClass.newInstance();

        Method setUid = aClass.getDeclaredMethod("setUid", String.class);
        setUid.invoke(o,pro.getProperty("uid"));

        Method setUsername = aClass.getDeclaredMethod("setUsername", String.class);
        setUsername.invoke(o,pro.getProperty("username"));

        Method setPassword = aClass.getDeclaredMethod("setPassword", String.class);
        setPassword.invoke(o,pro.getProperty("password"));

        System.out.println(o);
    }
}
